home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / callback.001 / callback~ / callback / lib / dest / getbuf.c < prev    next >
C/C++ Source or Header  |  1996-07-22  |  627b  |  37 lines

  1.  
  2. #include "dest.p"
  3.  
  4. char *getbuf(char *buf, unsigned buflen)
  5. {
  6.     int
  7.     idx,
  8.     c = '\n';
  9.     register char
  10.     *cp;
  11.  
  12.     buflen--;                /* room for the final 0 */
  13.  
  14.     for (cp = buf, idx = 0; idx < buflen; idx++)    /* read a buffer */
  15.     {
  16.     c = getchar();            /* fetch a char */
  17.  
  18.     if (c == '\n')            /* read until \n */
  19.         break;
  20.  
  21.     *cp++ = (char)c;        /* store the char */
  22.     }
  23.  
  24.     while (c != '\n')            /* keep reading until EOF or \n */
  25.     c = getchar();
  26.  
  27.     *cp = 0;                /* terminate the number */
  28.  
  29.     return
  30.     (
  31.     *buf ?                /* something entered ? */
  32.         buf                /* then return buf */
  33.     :
  34.         NULL            /* else return NULL */
  35.     );
  36. }
  37.